//
//  TSRechargeInfoTableViewCell.swift
//  TSProfitProject
//
//  Created by TMS on 2019/11/6.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit
import HandyJSON
import SDWebImage

struct TSRechargeModel : HandyJSON {
    var id : Int = 0
    var usdt_dres : String?
    var ustd : String?
    var ustd_img : String?
}

class TSRechargeInfoTableViewCell: UITableViewCell {
    
    private var model : TSRechargeModel!
    private var qrImg : UIImageView!
    private var walletContentLabel : UILabel!
    private var copyBtn : UIButton!
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        configViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupCell(model:TSRechargeModel) {
        
        self.model = model
        
        walletContentLabel.text = model.usdt_dres
        qrImg.sd_setImage(with: URL(string: model.ustd_img ?? ""), completed: nil)
        
        copyBtn.isEnabled = self.model.usdt_dres?.count ?? 0 > 0
    }
    
    @objc func copyAction() {
        
        
        if self.model.usdt_dres?.count ?? 0 > 0 {
            CBToast.showToastAction(message: "复制成功")
            let pasteboard = UIPasteboard.general
            pasteboard.string = self.model.usdt_dres
        }
    }
    
    func configViews() {
        
        let typeLabel = UILabel.init()
        typeLabel.text = "收款方式     USDT"
        typeLabel.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        typeLabel.textColor = UIColor.hexadecimalColor(hexadecimal: "#282828")
        self.contentView.addSubview(typeLabel)
        typeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(26)
            make.top.equalTo(23)
        }
        
        let codeLabel = UILabel.init()
        codeLabel.text = "收款码"
        codeLabel.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        codeLabel.textColor = UIColor.hexadecimalColor(hexadecimal: "#282828")
        self.contentView.addSubview(codeLabel)
        codeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(typeLabel)
            make.top.equalTo(typeLabel.snp_bottom).offset(23)
            
        }

        qrImg = UIImageView.init()
        self.contentView.addSubview(qrImg)
        qrImg.snp.makeConstraints { (make) in
            make.left.equalTo(codeLabel.snp_right).offset(33)
            make.top.equalTo(codeLabel)
            make.size.equalTo(CGSize(width: 172, height: 172))
        }

        let walletLabel = UILabel.init()
        walletLabel.text = "收款钱包"
        walletLabel.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        walletLabel.textColor = UIColor.hexadecimalColor(hexadecimal: "#282828")
        self.contentView.addSubview(walletLabel)
        walletLabel.snp.makeConstraints { (make) in
            make.left.equalTo(typeLabel)
            make.top.equalTo(qrImg.snp_bottom).offset(25)
        }

        walletContentLabel = UILabel.init()
        walletContentLabel.numberOfLines = 0
        walletContentLabel.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        walletContentLabel.textColor = UIColor.hexadecimalColor(hexadecimal: "#282828")
        self.contentView.addSubview(walletContentLabel)
        walletContentLabel.snp.makeConstraints { (make) in
            make.left.equalTo(102)
            make.right.equalToSuperview().inset(26)
            make.top.equalTo(walletLabel)
        }
        
        copyBtn = UIButton.init(type: .system)
        copyBtn.setTitle("一键复制", for: .normal)
        copyBtn.setTitleColor(WHITE_COLOR, for: .normal)
        copyBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        copyBtn.backgroundColor = BASE_PURPLE_COLOR
        copyBtn.layer.cornerRadius = 14
        copyBtn.layer.masksToBounds = true
        copyBtn.addTarget(self, action: #selector(copyAction), for: .touchUpInside)
        self.contentView.addSubview(copyBtn)
        copyBtn.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(walletContentLabel.snp_bottom).offset(25)
            make.size.equalTo(CGSize(width: SCREEN_WIDTH*0.208, height: 28))
        }

        let infoLabel = UILabel.init()
        infoLabel.text = "扫码支付或者钱包支付"
        infoLabel.textColor = BASE_RED_COLOR
        infoLabel.font = UIFont.systemFont(ofSize: 10, weight: .medium)
        self.contentView.addSubview(infoLabel)
        infoLabel.snp.makeConstraints { (make) in
            make.right.equalToSuperview().inset(12)
            make.top.equalTo(copyBtn.snp_bottom).offset(10)
            
            make.bottom.equalTo(-23)
        }
    }

}
